﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MaxLeaf.Common;
using MySql.Data.MySqlClient;
using MaxLeaf.DB;

namespace MaxLeaf.DAL.Web
{
    /// <summary>
    /// 商品属性分类表，用于扩展商品属性
    /// </summary>
    public class mary_attributeDAL
    {
        public string Getattr_id( DBAccess dbCon, string strattr_name)
        {
            DataRow drData = dbCon.GetTableDataFirstRow( "mary_attribute", new Dictionary<string, object> { { "attr_name", strattr_name } });

              
            if (drData != null)
            {
                return CvtFunc.ToString(drData["attr_id"]);
            }

            return Add(dbCon, strattr_name);
        }

        public string Add(DBAccess dbCon, string strattr_name)
        {
            string strSql = "insert into mary_attribute(attr_name,cat_id, attr_input_type, attr_type      ) values(?attr_name,1,0,0);select  @@identity";
            MySqlParameter[] arrParam = new MySqlParameter[] { 
                new MySqlParameter("?attr_name", strattr_name)                 
            };
            return dbCon.GetValue( strSql, arrParam);
            
        }

        

    }
}
